{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.1. Learning the basics of the Unix shell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:38.893804Z",
     "start_time": "2023-10-20T12:45:38.864405Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "'/Users/jarvis/source/pythonPrj/cookbook-2nd-code/chapter02_best_practices'"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:38.989715Z",
     "start_time": "2023-10-20T12:45:38.869610Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "01_py3.ipynb           04_git_advanced.ipynb  07_high_quality.ipynb\r\n",
      "01_shell.ipynb         05_tips.ipynb          07_test.ipynb\r\n",
      "02_py3.ipynb           05_workflows.ipynb     08_debugging.ipynb\r\n",
      "02_workflows.ipynb     06_high_quality.ipynb  08_test.ipynb\r\n",
      "03_git.ipynb           06_tips.ipynb          09_debugging.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.113252Z",
     "start_time": "2023-10-20T12:45:38.990272Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 200\r\n",
      "-rw-r--r--@ 1 jarvis  staff  13325 Oct 20 20:45 01_py3.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff   6769 Nov 20  2022 01_shell.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff  10016 Nov 20  2022 02_py3.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    212 Nov 20  2022 02_workflows.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff   5245 Nov 20  2022 03_git.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff   6680 Nov 20  2022 04_git_advanced.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    228 Nov 20  2022 05_tips.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    217 Nov 20  2022 05_workflows.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    906 Nov 20  2022 06_high_quality.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    233 Nov 20  2022 06_tips.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    901 Nov 20  2022 07_high_quality.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff   4697 Nov 20  2022 07_test.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    666 Nov 20  2022 08_debugging.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff   4692 Nov 20  2022 08_test.ipynb\r\n",
      "-rw-r--r--@ 1 jarvis  staff    666 Nov 20  2022 09_debugging.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.127990Z",
     "start_time": "2023-10-20T12:45:39.114705Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Errno 2] No such file or directory: 'images'\n",
      "/Users/jarvis/source/pythonPrj/cookbook-2nd-code/chapter02_best_practices\n"
     ]
    }
   ],
   "source": [
    "cd images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.128273Z",
     "start_time": "2023-10-20T12:45:39.118190Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "'/Users/jarvis/source/pythonPrj/cookbook-2nd-code/chapter02_best_practices'"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.256383Z",
     "start_time": "2023-10-20T12:45:39.122082Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "01_py3.ipynb           04_git_advanced.ipynb  07_high_quality.ipynb\r\n",
      "01_shell.ipynb         05_tips.ipynb          07_test.ipynb\r\n",
      "02_py3.ipynb           05_workflows.ipynb     08_debugging.ipynb\r\n",
      "02_workflows.ipynb     06_high_quality.ipynb  08_test.ipynb\r\n",
      "03_git.ipynb           06_tips.ipynb          09_debugging.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.257281Z",
     "start_time": "2023-10-20T12:45:39.244726Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Users/jarvis/source/pythonPrj/cookbook-2nd-code\n"
     ]
    }
   ],
   "source": [
    "cd .."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.257568Z",
     "start_time": "2023-10-20T12:45:39.250524Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "'/Users/jarvis/source/pythonPrj/cookbook-2nd-code'"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.378142Z",
     "start_time": "2023-10-20T12:45:39.256798Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 0\r\n",
      "drwxr-xr-x@  3 jarvis  staff    96 Nov 20  2022 \u001B[34m.\u001B[m\u001B[m/\r\n",
      "drwxr-xr-x@ 61 jarvis  staff  1952 Oct 19 23:23 \u001B[34m..\u001B[m\u001B[m/\r\n",
      "drwxr-xr-x@  8 jarvis  staff   256 Oct 20 20:45 \u001B[34mprofile_default\u001B[m\u001B[m/\r\n"
     ]
    }
   ],
   "source": [
    "ls -la ~/.ipython"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.388440Z",
     "start_time": "2023-10-20T12:45:39.380831Z"
    }
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (4083471220.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001B[0;36m  Cell \u001B[0;32mIn[10], line 2\u001B[0;36m\u001B[0m\n\u001B[0;31m    mkdir md_files\u001B[0m\n\u001B[0m          ^\u001B[0m\n\u001B[0;31mSyntaxError\u001B[0m\u001B[0;31m:\u001B[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# We create an empty directory:\n",
    "mkdir md_files\n",
    "# We copy all Markdown files into the new directory:\n",
    "cp *.md md_files\n",
    "# We rename the directory:\n",
    "mv md_files markdown_files\n",
    "ls markdown_files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:45:39.385327Z"
    }
   },
   "outputs": [],
   "source": [
    "rmdir markdown_files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:45:39.386799Z"
    }
   },
   "outputs": [],
   "source": [
    "rm markdown_files/*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.388835Z",
     "start_time": "2023-10-20T12:45:39.388671Z"
    }
   },
   "outputs": [],
   "source": [
    "rmdir markdown_files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:45:39.390082Z"
    }
   },
   "outputs": [],
   "source": [
    "# Show the first three lines of a text file:\n",
    "head -n 3 01_shell.md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.392688Z",
     "start_time": "2023-10-20T12:45:39.391350Z"
    }
   },
   "outputs": [],
   "source": [
    "# Show the last line of a text file:\n",
    "tail -n 1 00_intro.md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:45:39.392559Z"
    }
   },
   "outputs": [],
   "source": [
    "# We display some text:\n",
    "echo \"Hello world!\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:45:39.393758Z",
     "start_time": "2023-10-20T12:45:39.393430Z"
    }
   },
   "outputs": [],
   "source": [
    "# We redirect the output of a command to\n",
    "# a text file with `>`:\n",
    "echo \"Hello world!\" > myfile.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:45:39.394247Z"
    }
   },
   "outputs": [],
   "source": [
    "# We display the entire contents of the file:\n",
    "cat myfile.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:45:39.395140Z"
    }
   },
   "outputs": [],
   "source": [
    "grep -Eo \"Unix \\w+\" 01_shell.md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:45:39.396059Z"
    }
   },
   "outputs": [],
   "source": [
    "echo \"This is a Unix shell\" | grep -Eo \"Unix \\w+\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "language": "python",
   "display_name": "Python 3 (ipykernel)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
